//
// Created by hunan on 25-7-13.
//

#ifndef DOWNLOAD_FILE_OPERATE_H
#define DOWNLOAD_FILE_OPERATE_H
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include <map>

class DownloadFragment;
class FileHandle;
class DownloadRate;
class DownloadFileOperate
{
public:
    enum EmFileOperate
    {
        EmFileOperateInit = 0,
        EmFileOperateHasFileContent,
        EmFileOperateNothing,
    };
    struct FileData
    {
        std::string m_file_name;
        uint64_t    m_file_size;
    };
public:
    explicit DownloadFileOperate(FileData & data);
    int  InitDownloadFileOperate();
    bool IsLargeFile() const;
    bool GetOneFragment(int & min, int & max) const;
    void PushFileData(int min, int max, const uint8_t * data, int data_size);
    void DownFileDataFail(int min, int max) const;
    uint64_t           GetLocalFileSize() const;
    uint64_t           GetRemoteFileSize() const;
    std::string GetLocalFileHash() const;
    bool DownloadAll() const;
    void WriteToFile();
    void PrintStatistic() const;
private:
    FileData                            m_file_data{};
    std::shared_ptr<DownloadFragment>   m_fragment{};
    std::shared_ptr<FileHandle>         m_file_handle{};
    std::shared_ptr<DownloadRate>       m_rate{};
    std::map<int, std::vector<uint8_t>> m_data_vec_map;
    int                                 m_start_index{};
};



#endif //DOWNLOAD_FILE_OPERATE_H
